﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace AI
{
	// Token: 0x02000205 RID: 517
	public class MicroDecisionMaker : DecisionMaker
	{
		// Token: 0x06000AFA RID: 2810 RVA: 0x0005CF7D File Offset: 0x0005B17D
		public MicroDecisionMaker(Humanoid entity) : base(entity)
		{
		}

		// Token: 0x06000AFB RID: 2811 RVA: 0x0005CF94 File Offset: 0x0005B194
		public override void Execute()
		{
			if (this.entity.locked || !this.entity.CanDecide())
			{
				return;
			}
			if (this.ai.IsIdle())
			{
				this.MakeDecision(false);
			}
			else if (this.lastDecision != null && !this.lastDecision.IsReactive() && Time.time > this.lastCheck + this.checkInterval)
			{
				this.MakeDecision(true);
			}
		}

		// Token: 0x06000AFC RID: 2812 RVA: 0x0005D018 File Offset: 0x0005B218
		public void MakeDecision(bool onlyReactive = false)
		{
			this.lastCheck = Time.time;
			this.ai.mentalState.Update();
			EntityBase entityBase = this.ai.mentalState.ChooseTarget();
			List<TargetType> agentDefs = BehaviorLists.Instance.FindDefs(this.entity, null);
			List<TargetType> list = BehaviorLists.Instance.FindDefs(entityBase, null);
			list.Add(TargetType.Oneself);
			list.Add(TargetType.None);
			List<IBehavior> list2 = BehaviorLists.Instance.FindBehaviors(agentDefs, list);
			list2 = list2.FindAll((IBehavior beh) => beh.IsAI() && (beh.IsReactive() || !onlyReactive));
			IBehavior behavior = base.ChooseBehavior(list2);
			if (behavior == null)
			{
				return;
			}
			this.lastDecision = behavior;
			if (onlyReactive)
			{
				this.ai.ImmediateCommand(this.lastDecision, entityBase, base.getRandomPoint());
			}
			else
			{
				this.ai.ScheduleCommand(this.lastDecision, entityBase, base.getRandomPoint());
			}
		}

		// Token: 0x04001012 RID: 4114
		private float lastCheck;

		// Token: 0x04001013 RID: 4115
		private float checkInterval = 1f;

		// Token: 0x04001014 RID: 4116
		private IBehavior lastDecision;
	}
}
